package com.github;

import com.github.sub.inter.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wangyadong
 * @date 2021/10/25 13:29
 */
public class InterfaceCommander extends Common implements Commander {

    private static final Map<String, Commander> MAP = new HashMap<>();


    static {
        MAP.put("-e", new ExeCommander());
        MAP.put("-h", new HeaderCommander());
        MAP.put("-a", new AliasCommander());
        MAP.put("-m", new MethodCommander());
        MAP.put("-p", new ParamCommander());
    }

    @Override
    public Object run(Map<String, String> command) {
        command.forEach((k, v) -> {
            Commander commander = MAP.get(k);
            if (commander == null) {
                if (!k.equals("-pa")) {
                    System.out.println(k + notFound);
                }
            } else {
                commander.run(command);
            }
        });
        return null;
    }


    public static void main(String[] args) {
        InterfaceCommander commaner = new InterfaceCommander();
        //创建接口 取别名version
//        commaner.operation("-alias", "/scheme/list slist");
//        //接口 添加header
//        commaner.operation("-header", "slist Content-Type:application/json;charset=UTF-8");
//        commaner.operation("-method", "slist POST");
//        commaner.operation("-param", "query   -pa 10106573={\"dataSource\": \"icome\",\"dataTable\": \"hr_valuecreation_individual_board_h\",\"filter\": {\"fields\": [{ \"field\": \"year\", \"type\": \"selector\", \"value\": \"2021\"},{  \"field\": \"pernr\", \"type\": \"selector\",\"value\": \"10106573\" },{ \"field\": \"quarter\", \"type\": \"in\", \"values\": [ \"Q3\" ] }, { \"field\": \"month\", \"type\": \"in\", \"values\": [\"07\", \"08\", \"09\" ]}, { \"field\": \"kpi_id\", \"type\": \"in\", \"values\": [\"kpi_019\", \"kpi_031\" ] } ], \"type\": \"and\" }, \"limitLower\": 0,  \"limitUpper\": 100, \"queryType\": \"query\", \"returnFields\": [ \"pernr\",  \"month\",   \"quarter\",    \"year\",   \"kpi_id\",   \"kpi_note\",   \"value\" ], \"userKey\": \"16e74400-8359-4d13-ace7-b9d98fb2a687\"}] ");
        //执行接口
//        commaner.operation("-e", "login-t  -p liudan ");
//        Map<String, String> map = commaner.valueToMap("-e login-t  -p liudan ");
//        System.out.println(map);

        Map<String, String> map = new HashMap<>();
        map.put("-e", "log");
        map.put("-pa", "pp");
//        commaner.run(map);
    }


}
